<?php defined('SYSPATH') OR die('No direct access allowed.');

class Content_Model extends Model {
	
	protected $db;
	public $a_Content;
	
	public function __construct(){
		parent::__construct();
		
		$this->db = new Database();
	}
	
	private function get_title($i_Active){
		$records = $this->db->select('ID, name')->from('menu')->where('ID', ($i_Active+1))->get();
		
		if ($records->count()){
			foreach ($records as $row){
				$a_Category[($row->ID)-1]['name'] = $row->name;
			}
			//$a_Category = $records->name;
			//$a_Category = $records['name'];
			return $a_Category[$i_Active]['name'];
		}
		else{
			return FALSE;
		}
	}
	
	private function get_main_menu($i_Active){
		$records = $this->db->select('ID, name, link')->from('menu')->get();
		
		if ($records->count()){
			foreach ($records as $row){
				$a_Menu[($row->ID)-1]['name'] = $row->name;
				$a_Menu[($row->ID)-1]['link'] = $row->link;
			}
			$a_Menu[$i_Active]['active'] = 1;
			
			return $a_Menu;
		}
		else{
			return FALSE;
		}
	}

	private function get_submenu($i_Active, $i_Subactive){
		$records = $this->db->select('ID, name, link')->from('submenu')->where('menu_ID', $i_Active+1)->get();
		
		if ($records->count()){
			$i=0;
			foreach ($records as $row){
				$a_Submenu[$i]['name'] = $row->name;
				$a_Submenu[$i]['link'] = $row->link;
				$i++;
			}
			$a_Submenu[$i_Subactive]['active'] = 1;
			
			return $a_Submenu;
		}
		else{
			return FALSE;
		}
	}
	
	
	
	public function get_content($i_Active, $i_Subactive){
		$this->a_Content['title'] = $this->get_title($i_Active);
		$this->a_Content['main_menu'] = $this->get_main_menu($i_Active);
		$this->a_Content['submenu'] = $this->get_submenu($i_Active, $i_Subactive);
	//	$this->a_Content['sections'] = get_sections($i_Active, $i_Subactive);
	}
}

?>